package cn.javaweb.servlet;

import cn.javaweb.entity.LoginInfo;
import cn.javaweb.entity.SigninInfo;
import cn.javaweb.entity.User;
import cn.javaweb.library.AjaxResult;
import cn.javaweb.library.Util;
import cn.javaweb.model.CourseModel;
import com.alibaba.fastjson2.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/student/signin")
public class SigninServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        try{

            SigninInfo si = JSON.parseObject(Util.getJsonParam(req), SigninInfo.class);

            User user = (User) req.getAttribute("user");
            CourseModel courseModel = new CourseModel();

            courseModel.signin(si.getCid(), user.getId());
            resp.getWriter().print(AjaxResult.success("操作成功"));


        }catch (Exception e){
            resp.setContentType("application/json;charset=UTF-8;");
            resp.getWriter().print(AjaxResult.error("登陆失败"));
        }


    }
}
